package com.dfbz.demo01_卖票案例;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo10_守护线程 {
    public static void main(String[] args) {


        Thread t1 = new Thread("A") {
            @Override
            public void run() {
                for (int i = 0; i <= 10000; i++) {
                    System.out.println(Thread.currentThread().getName()+i);
                }
            }
        };

        Thread t2 = new Thread("B") {
            @Override
            public void run() {
                for (int i = 0; i <= 10000; i++) {

                    if(i==100){
                        try {
                            t1.join();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                    System.out.println(Thread.currentThread().getName()+i);
                }
            }
        };

        // t2设置为守护线程
        t2.setDaemon(true);

        t1.start();
        t2.start();
    }
}
